package com.ruoyi.factorydata.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.factorydata.domain.MaterialInventoryFlow;
import com.ruoyi.factorydata.service.IMaterialInventoryFlowService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 物料库存流水Controller
 * 
 * @author ruoyi
 * @date 2025-07-23
 */
@RestController
@RequestMapping("/warehouse/materialInventoryFlow")
public class MaterialInventoryFlowController extends BaseController
{
    @Autowired
    private IMaterialInventoryFlowService materialInventoryFlowService;

    /**
     * 查询物料库存流水列表
     */
    @PreAuthorize("@ss.hasPermi('warehouse:materialInventoryFlow:list')")
    @GetMapping("/list")
    public TableDataInfo list(MaterialInventoryFlow materialInventoryFlow)
    {
        startPage();
        List<MaterialInventoryFlow> list = materialInventoryFlowService.selectMaterialInventoryFlowList(materialInventoryFlow);
        return getDataTable(list);
    }

    /**
     * 导出物料库存流水列表
     */
    @PreAuthorize("@ss.hasPermi('warehouse:materialInventoryFlow:export')")
    @Log(title = "物料库存流水", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MaterialInventoryFlow materialInventoryFlow)
    {
        List<MaterialInventoryFlow> list = materialInventoryFlowService.selectMaterialInventoryFlowList(materialInventoryFlow);
        ExcelUtil<MaterialInventoryFlow> util = new ExcelUtil<MaterialInventoryFlow>(MaterialInventoryFlow.class);
        util.exportExcel(response, list, "物料库存流水数据");
    }

    /**
     * 获取物料库存流水详细信息
     */
    @PreAuthorize("@ss.hasPermi('warehouse:materialInventoryFlow:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(materialInventoryFlowService.selectMaterialInventoryFlowById(id));
    }

    /**
     * 新增物料库存流水
     */
    @PreAuthorize("@ss.hasPermi('warehouse:materialInventoryFlow:add')")
    @Log(title = "物料库存流水", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MaterialInventoryFlow materialInventoryFlow)
    {
        return toAjax(materialInventoryFlowService.insertMaterialInventoryFlow(materialInventoryFlow));
    }

    /**
     * 修改物料库存流水
     */
    @PreAuthorize("@ss.hasPermi('warehouse:materialInventoryFlow:edit')")
    @Log(title = "物料库存流水", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MaterialInventoryFlow materialInventoryFlow)
    {
        return toAjax(materialInventoryFlowService.updateMaterialInventoryFlow(materialInventoryFlow));
    }

    /**
     * 删除物料库存流水
     */
    @PreAuthorize("@ss.hasPermi('warehouse:materialInventoryFlow:remove')")
    @Log(title = "物料库存流水", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(materialInventoryFlowService.deleteMaterialInventoryFlowByIds(ids));
    }
}
